package com.gitee.wsl.mathematics.algebraic

import com.gitee.wsl.mathematics.algebraic.number.NumericAlgebra
import com.gitee.wsl.mathematics.algebraic.op.PowerOperations


/**
 * Advanced Number-like field that implements basic operations.
 */
interface ExtendedField<T> : ExtendedFieldOps<T>, Field<T>, NumericAlgebra<T> {
    override fun sinh(arg: T): T = (exp(arg) - exp(-arg)) / 2.0
    override fun cosh(arg: T): T = (exp(arg) + exp(-arg)) / 2.0
    override fun tanh(arg: T): T = (exp(arg) - exp(-arg)) / (exp(-arg) + exp(arg))
    override fun asinh(arg: T): T = ln(sqrt(arg * arg + one) + arg)
    override fun acosh(arg: T): T = ln(arg + sqrt((arg - one) * (arg + one)))
    override fun atanh(arg: T): T = (ln(arg + one) - ln(one - arg)) / 2.0

    override fun unaryOperationFunction(operation: String): (arg: T) -> T {
        return if (operation == PowerOperations.SQRT_OPERATION) ::sqrt
        else super<ExtendedFieldOps>.unaryOperationFunction(operation)
    }

    override fun rightSideNumberOperationFunction(operation: String): (left: T, right: Number) -> T =
        when (operation) {
            PowerOperations.POW_OPERATION -> ::power
            else -> super<Field>.rightSideNumberOperationFunction(operation)
        }
}

